package com.seeyon.apps.kanban.manager.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.seeyon.apps.brwh.kit.FormCap4Kit;
import com.seeyon.apps.brwh.kit.StrKit;
import com.seeyon.apps.kanban.enums.FileTableEnum;
import com.seeyon.apps.kanban.enums.MilestoneEnum;
import com.seeyon.apps.kanban.enums.ProjectLevelEnum;
import com.seeyon.apps.kanban.manager.IpdKanBanDataManager;
import com.seeyon.cap4.form.bean.FormBean;
import com.seeyon.cap4.form.bean.FormFieldBean;
import com.seeyon.cap4.form.bean.FormTableBean;
import com.seeyon.cap4.form.service.CAP4FormManager;
import com.seeyon.cap4.template.manager.CAPDataListSqlHelpManager;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.ctpenum.dao.cache.CtpEnumItemCache;
import com.seeyon.ctp.common.ctpenumnew.manager.EnumManager;
import com.seeyon.ctp.common.dump.vo.DumpDataVO.dataType;
import com.seeyon.ctp.common.exceptions.BusinessException;
import com.seeyon.ctp.common.log.CtpLogFactory;
import com.seeyon.ctp.common.po.ctpenumnew.CtpEnumItem;
import com.seeyon.ctp.organization.bo.V3xOrgMember;
import com.seeyon.ctp.organization.manager.OrgManager;
import com.seeyon.ctp.rest.resources.KanBanDataIPDResourcces;
import com.seeyon.ctp.util.Strings;
import org.apache.commons.logging.Log;
import com.seeyon.cap4.form.modules.engin.manager.CapFormDefinitionManager;
import com.seeyon.cap4.form.po.CAPFormDefinition;

import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;

public class IpdKanBanDataManagerImpl implements IpdKanBanDataManager {

    private static final Log log = CtpLogFactory.getLog(KanBanDataIPDResourcces.class);
    private CapFormDefinitionManager capFormDefinitionManager = (CapFormDefinitionManager)AppContext.getBean("capFormDefinitionManager");


    /* 创建日期格式化对象，用于解析日期字符串 */
    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    /*开发状态*/
    private static final String kfStatus = AppContext.getSystemProperty("kanban.kfStatus");

    private OrgManager orgManager = (OrgManager) AppContext.getBean("orgManager");
    private EnumManager enumManager = (EnumManager) AppContext.getBean("enumManagerNew");
    private CAP4FormManager cap4FormManager = (CAP4FormManager) AppContext.getBean("cap4FormManager");
    private CAPDataListSqlHelpManager capDataListSqlHelpManager = (CAPDataListSqlHelpManager) AppContext.getBean("capDataListSqlHelpManager");
    private static CtpEnumItemCache ctpEnumItemCache = (CtpEnumItemCache) AppContext.getBean("ctpEnumItemCache");

    /**
     * 根据枚举项代码获取枚举项对象。
     * 此方法用于通过枚举项的代码值查找并返回相应的枚举项对象。如果找不到匹配的枚举项，将返回null。
     * 如果传入的枚举项代码为空或空白字符串，也将直接返回null。
     *
     * @param itmeCode 枚举项的代码字符串。
     * @return 匹配的枚举项对象，如果找不到则返回null。
     * @throws BusinessException 如果操作过程中出现业务异常。
     */
    @Override
    public CtpEnumItem getEnumByCode(String itmeCode) throws BusinessException {
        // 检查输入的枚举项代码是否为空或空白字符串
        if (Strings.isBlank(itmeCode)) {
            return null;
        } else {
            // 初始化一个账户ID变量，用于后续比较
            Long accountId = null;
            // 遍历枚举项缓存中的所有条目
            Iterator var4 = ctpEnumItemCache.findAll().iterator();

            while (var4.hasNext()) {
                CtpEnumItem entry = (CtpEnumItem) var4.next();
                // 如果accountId为null，且当前枚举项的代码与输入代码匹配，则返回该枚举项
                if (accountId == null) {
                    if (itmeCode.equals(entry.getEnumItemCode())) {
                        return entry;
                    }
                } else if (itmeCode.equals(entry.getEnumItemCode())) {
                    // 如果accountId不为null，且当前枚举项的代码与输入代码匹配，则返回该枚举项
                    return entry;
                }
            }

            // 如果遍历完成后仍未找到匹配的枚举项，则返回null
            return null;
        }
    }


    /**
     * 将临时数据转换为真实数据。
     * 此方法接收一个字符串参数，该参数是一个JSON数组的字符串表示。方法解析这个数组，
     * 对其中的每个对象进行处理，统计各类型数据的“cqNum”和“lqNum”字段的总和，
     * 最后返回一个映射，其中包含了每种类型的数据统计。
     *
     * @param str 输入的JSON数组字符串，包含临时数据。
     * @return 返回一个映射，映射的键是数据类型（如"xm"、"tp"等），值是另一个映射，
     * 这个映射的键是"cqNum"和"lqNum"，值是对应类型的“cqNum”和“lqNum”字段的总和。
     * @throws BusinessException 如果处理过程中出现业务错误，抛出此异常。
     */
    @Override
    public Map<String, Object> tempToTureData(String str) throws BusinessException {
        // 解析输入的字符串为JSON数组
        JSONArray jsonArray = JSONArray.parseObject(str, JSONArray.class);

        // 初始化各种类型数据的“cqNum”和“lqNum”计数器
        int xm_cqNum = 0;
        int xm_lqNum = 0;
        int tp_cqNum = 0;
        int tp_lqNum = 0;
        int sj_cqNum = 0;
        int sj_lqNum = 0;
        int dy_cqNum = 0;
        int dy_lqNum = 0;
        int zb_cqNum = 0;
        int zb_lqNum = 0;

        // 遍历JSON数组中的每个对象
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject obj = jsonArray.getJSONObject(i);

            // 如果对象包含"xm"字段，提取并累加"xm"类型的"cqNum"和"lqNum"
            if (obj.containsKey("xm")) {
                JSONObject xm = obj.getJSONObject("xm");
                xm_cqNum += xm.getInteger("cqNum");
                xm_lqNum += xm.getInteger("lqNum");
            }

            // 如果对象包含"tp"字段，提取并累加"tp"类型的"cqNum"和"lqNum"
            if (obj.containsKey("tp")) {
                JSONObject tp = obj.getJSONObject("tp");
                tp_cqNum += tp.getInteger("cqNum");
                tp_lqNum += tp.getInteger("lqNum");
            }

            // 如果对象包含"sj"字段，提取并累加"sj"类型的"cqNum"和"lqNum"
            if (obj.containsKey("sj")) {
                JSONObject sj = obj.getJSONObject("sj");
                sj_cqNum += sj.getInteger("cqNum");
                sj_lqNum += sj.getInteger("lqNum");
            }

            // 如果对象包含"dy"字段，提取并累加"dy"类型的"cqNum"和"lqNum"
            if (obj.containsKey("dy")) {
                JSONObject dy = obj.getJSONObject("dy");
                dy_cqNum += dy.getInteger("cqNum");
                dy_lqNum += dy.getInteger("lqNum");
            }

            // 如果对象包含"zb"字段，提取并累加"zb"类型的"cqNum"和"lqNum"
            if (obj.containsKey("zb")) {
                JSONObject zb = obj.getJSONObject("zb");
                zb_cqNum += zb.getInteger("cqNum");
                zb_lqNum += zb.getInteger("lqNum");
            }
        }

        // 创建一个映射，用于存放最终的结果
        Map<String, Object> dataMap = new HashMap<String, Object>();

        // 将"xm"类型的统计结果添加到dataMap中
        Map<String, Object> xmMap = new HashMap<String, Object>();
        xmMap.put("cqNum", xm_cqNum);
        xmMap.put("cqUrl", "/seeyon/vreport/vReport.do?method=showReport&id=1069640353002244397&module=2&type=2");
        xmMap.put("lqNum", xm_lqNum);
        xmMap.put("lqUrl", "/seeyon/vreport/vReport.do?method=showReport&id=-3548444371541342169&module=2&type=2");
        dataMap.put("xm", xmMap);

        // 将"tp"类型的统计结果添加到dataMap中
        Map<String, Object> tpMap = new HashMap<String, Object>();
        tpMap.put("cqNum", tp_cqNum);
        tpMap.put("cqUrl", "/seeyon/vreport/vReport.do?method=showReport&id=-601350684921805965&module=2&type=2");
        tpMap.put("lqNum", tp_lqNum);
        tpMap.put("lqUrl", "/seeyon/vreport/vReport.do?method=showReport&id=-1818950433076786760&module=2&type=2");
        dataMap.put("tp", tpMap);

        // 将"sj"类型的统计结果添加到dataMap中
        Map<String, Object> sjMap = new HashMap<String, Object>();
        sjMap.put("cqNum", sj_cqNum);
        sjMap.put("cqUrl", "/seeyon/vreport/vReport.do?method=showReport&id=931512928886606959&module=2&type=2");
        sjMap.put("lqNum", sj_lqNum);
        sjMap.put("lqUrl", "/seeyon/vreport/vReport.do?method=showReport&id=3775353492983729734&module=2&type=2");
        dataMap.put("sj", sjMap);

        // 将"dy"类型的统计结果添加到dataMap中
        Map<String, Object> dyMap = new HashMap<String, Object>();
        dyMap.put("cqNum", dy_cqNum);
        dyMap.put("cqUrl", "/seeyon/vreport/vReport.do?method=showReport&id=-8299300284150757408&module=2&type=2");
        dyMap.put("lqNum", dy_lqNum);
        dyMap.put("lqUrl", "/seeyon/vreport/vReport.do?method=showReport&id=4282086126098727040&module=2&type=2");
        dataMap.put("dy", dyMap);

        // 将"zb"类型的统计结果添加到dataMap中
        Map<String, Object> zbMap = new HashMap<String, Object>();
        zbMap.put("cqNum", zb_cqNum);
        zbMap.put("cqUrl", "/seeyon/vreport/vReport.do?method=showReport&id=-6208342256724129883&module=2&type=2");
        zbMap.put("lqNum", zb_lqNum);
        zbMap.put("lqUrl", "/seeyon/vreport/vReport.do?method=showReport&id=-5296142996306113983&module=2&type=2");
        dataMap.put("zb", zbMap);

        // 返回最终的统计结果
        return dataMap;
    }


    /**
     * 计算项目预警指标中超期和临期的数量。
     * 通过遍历数据列表，比较每个项目的预期完成时间和实际完成时间来确定其状态（超期或临期）。
     *
     * @param dataList          数据列表，包含每个项目的预期和实际完成时间。
     * @param mainQwwcFieldName 表示预期完成时间的字段名。
     * @param mainSjwcFieldName 表示实际完成时间的字段名。
     * @return 包含超期和临期数量的映射。
     * @throws BusinessException 如果处理过程中出现业务异常。
     */
    public Map<String, Object> getxmyjzbCount(List dataList, String mainQwwcFieldName, String mainSjwcFieldName) throws BusinessException {
        /* 初始化用于存储超期和临期数量的映射 */
        Map<String, Object> numMap = new HashMap<String, Object>();
        try {
            /* 初始化超期和临期数量 */
            int cqNum = 0;
            int lqNum = 0;
            /* 当数据列表不为空时，进行处理 */
            if (!dataList.isEmpty()) {
                /* 遍历数据列表 */
                for (int i = 0; i < dataList.size(); i++) {
                    /* 将列表中的每个元素转换为Map对象 */
                    Map<String, Object> dataMap = (Map<String, Object>) dataList.get(i);
                    /* 从Map中获取预期和实际完成时间 */
                    /*期望完成时间*/
                    Object qwwcDateTime = dataMap.get(mainQwwcFieldName);
                    /*实际完成时间*/
                    Object sjwcDateTime = dataMap.get(mainSjwcFieldName);
                    /* 当预期和实际完成时间都不为空时，进行比较 */
                    if (!"".equals(StrKit.str(qwwcDateTime)) && !"".equals(StrKit.str(sjwcDateTime))) {
                        /* 将日期字符串解析为Date对象 */
                        Date qwwcDateTime_new = sdf.parse(qwwcDateTime.toString());
                        Date sjwcDateTime_new = sdf.parse(sdf.format(new Date()));
                        /* 比较预期和实际完成时间 */
                        int num = qwwcDateTime_new.compareTo(sjwcDateTime_new);
                        /* 如果预期完成时间晚于实际完成时间，则项目超期 */
                        if (num == 1) {
                            /* 计算当前时间与预期完成时间的间隔 */
                            Long qwwcDate = qwwcDateTime_new.getTime();
                            Long nowDate = new Date().getTime();
                            Long value = (nowDate - qwwcDate) / 24 / 60 / 60 / 1000;
                            /* 如果间隔大于等于5天，则认为是临期项目 */
                            if (value >= 5) {
                                lqNum += 1;
                            }
                        } else {
                            /* 如果实际完成时间晚于或等于预期完成时间，则项目正常，计数器加一 */
                            cqNum += 1;
                        }
                    }
                }
            }
            /* 将超期和临期数量存入映射中并返回 */
            numMap.put("cqNum", cqNum);
            numMap.put("lqNum", lqNum);
            return numMap;
        } catch (ParseException e) {
            /* 如果处理过程中出现解析异常，记录错误并返回空映射 */
            log.error("获取项目预警指标超期临期数量异常:", e);
            return numMap;
        }
    }


    /**
     * 获取预警指标超期/临期数量
     * 该方法用于计算推送产品的不同阶段（推品、设计、打样、制标）的预警指标中，超期和临期的数量。
     * 通过传入的数据列表和特定字段名，对每个阶段的完成时间进行比较，以确定是否超期或临期。
     *
     * @param dataList         数据列表，包含每个阶段的详细信息。
     * @param lcbFieldName     阶段类型字段名，用于确定当前处理的是哪个阶段的数据。
     * @param subQwwcFieldName 期望完成时间字段名。
     * @param subSjwcFieldName 实际完成时间字段名。
     * @return 返回一个Map，其中包含每个阶段的超期和临期数量。
     * @throws BusinessException 如果处理过程中出现业务异常。
     */
    public Map<String, Object> getyjzbOtherCount(List dataList, String lcbFieldName, String subQwwcFieldName, String subSjwcFieldName) throws BusinessException {
        /* 初始化结果数据的Map */
        Map<String, Object> resultDataMap = new HashMap<String, Object>();
        try {
            /* 检查数据列表是否为空 */
            if (!dataList.isEmpty()) {
                /* 初始化各阶段的超期和临期数量变量 */
                int tp_cqNum = 0;
                int sj_cqNum = 0;
                int dy_cqNum = 0;
                int zb_cqNum = 0;
                int tp_lqNum = 0;
                int sj_lqNum = 0;
                int dy_lqNum = 0;
                int zb_lqNum = 0;
                /* 遍历数据列表 */
                for (int i = 0; i < dataList.size(); i++) {
                    /* 获取当前数据项 */
                    Map<String, Object> dataMap = (Map<String, Object>) dataList.get(i);
                    /* 获取阶段类型 */
                    String lcbType = StrKit.str(dataMap.get(lcbFieldName));
                    /* 如果阶段类型为空，则跳过当前数据项 */
                    if ("".equals(lcbType)) {
                        continue;
                    }
                    /* 根据阶段类型获取对应的枚举项 */
                    CtpEnumItem lcbStatusEnum = enumManager.getCtpEnumItem(Long.parseLong(lcbType));
                    /* 获取枚举项的代码 */
                    String enumItemCode = StrKit.str(lcbStatusEnum.getEnumItemCode());
                    /* 获取期望完成时间和实际完成时间 */
                    /*期望完成时间*/
                    Object qwwcDateTime = dataMap.get(subQwwcFieldName);
                    /*实际完成时间*/
                    Object sjwcDateTime = dataMap.get(subSjwcFieldName);
                    /* 如果期望完成时间和实际完成时间都不为空 */
                    if (!"".equals(StrKit.str(qwwcDateTime)) && !"".equals(StrKit.str(sjwcDateTime))) {
                        /* 将时间字符串转换为Date对象 */
                        Date qwwcDateTime_new = sdf.parse(qwwcDateTime.toString());
                        Date sjwcDateTime_new = sdf.parse(sdf.format(new Date()));
                        /* 比较期望完成时间和实际完成时间 */
                        int num = qwwcDateTime_new.compareTo(sjwcDateTime_new);
                        /* 获取当前时间和期望完成时间的间隔 */
                        Long qwwcDate = qwwcDateTime_new.getTime();
                        Long nowDate = new Date().getTime();
                        Long value = (nowDate - qwwcDate) / 24 / 60 / 60 / 1000;
                        /* 根据阶段类型和时间比较结果，更新超期和临期数量 */
                        if ("LCB_TP".equals(enumItemCode)) {
                            if (num == 1) {
                                if (value >= 1) {
                                    tp_lqNum += 1;
                                }
                            } else {
                                tp_cqNum += 1;
                            }
                        }
                        if ("LCB_SJ".equals(enumItemCode)) {
                            if (num == 1) {
                                if (value >= 2) {
                                    sj_lqNum += 1;
                                }
                            } else {
                                sj_cqNum += 1;
                            }
                        }
                        if ("LCB_DY".equals(enumItemCode)) {
                            if (num == 1) {
                                if (value >= 4) {
                                    dy_lqNum += 1;
                                }
                            } else {
                                dy_cqNum += 1;
                            }
                        }
                        if ("LCB_ZB".equals(enumItemCode)) {
                            if (num == 1) {
                                if (value >= 2) {
                                    zb_lqNum += 1;
                                }
                            } else {
                                zb_cqNum += 1;
                            }
                        }
                    }
                }
                /* 将各阶段的超期和临期数量封装到Map中，并添加到结果数据的Map */
                /*推品超期/临期数量*/
                Map<String, Object> tpMap = new HashMap<String, Object>();
                tpMap.put("cqNum", tp_cqNum);
                tpMap.put("lqNum", tp_lqNum);
                resultDataMap.put("tp", tpMap);
                /*设计超期/临期数量*/
                Map<String, Object> sjMap = new HashMap<String, Object>();
                sjMap.put("cqNum", sj_cqNum);
                sjMap.put("lqNum", sj_lqNum);
                resultDataMap.put("sj", sjMap);
                /*打样超期/临期数量*/
                Map<String, Object> dyMap = new HashMap<String, Object>();
                dyMap.put("cqNum", dy_cqNum);
                dyMap.put("lqNum", dy_lqNum);
                resultDataMap.put("dy", dyMap);
                /*制标超期/临期数量*/
                Map<String, Object> zbMap = new HashMap<String, Object>();
                zbMap.put("cqNum", zb_cqNum);
                zbMap.put("lqNum", zb_lqNum);
                resultDataMap.put("zb", zbMap);
            }
            /* 返回结果数据的Map */
            return resultDataMap;
        } catch (ParseException e) {
            /* 记录解析异常日志，并返回空的结果数据Map */
            log.error("获取推品设计打样制标预警指标超期临期数量异常:", e);
            return resultDataMap;
        }
    }


    /**
     * 获取资源池使用情况统计数据
     * 该方法旨在通过查询不同表中的数据，统计资源池中各类资源的使用情况。具体包括产品经理的开发进度和里程碑的完成情况。
     * 数据统计基于表结构和预定义的查询条件，通过动态构建SQL语句来实现。
     *
     * @return 包含统计数据的Map对象，键为统计类型，值为具体的统计数据Map。
     * @throws BusinessException 如果查询过程中发生业务异常，则抛出此异常。
     */
    @Override
    public Map<String, Object> getzycsyqkCount() throws BusinessException {
        /* 初始化结果数据的Map */
        Map<String, Object> resultDataMap = new HashMap<String, Object>();
        try {
            /* 从系统属性中获取配置的产品经理、里程碑类型、状态和责任人字段名 */
            /* 产品经理 */
            String productManager = AppContext.getSystemProperty("kanban.productManager");
            /* 里程碑 */
            String lcbType = AppContext.getSystemProperty("kanban.lcbType");
            /* 里程碑状态(计划档案) */
            String lcbStatus = AppContext.getSystemProperty("kanban.lcbStatus");
            /* 里程碑责任人 */
            String person_in_charge = AppContext.getSystemProperty("kanban.person_in_charge");
            //项目来源
            String develop_source = AppContext.getSystemProperty("kanban.develop_source");
            //项目星级
            String project_rate = AppContext.getSystemProperty("kanban.project_rate");
            //是否里程碑字段描述
            String isLcb = AppContext.getSystemProperty("kanban.lcb_sf");
            //是否里程碑是
            String sfS = AppContext.getSystemProperty("kanban.sfS");
            CtpEnumItem qxEnum_sfS = FormCap4Kit.getEnumByCode(sfS);


            // 获取《研发项目档案》表单编号
            String yfxmda_formCode = AppContext.getSystemProperty("kanban.yfxmda_formCode");
            // 根据编码获取表单
            FormBean yfxmda_formBean = cap4FormManager.getFormByFormCode(yfxmda_formCode);
            //表单字段
            List<FormFieldBean> yfxmda_fieldBeans = yfxmda_formBean.getAllFieldBeans();
            /* 初始化产品经理和其他类型的统计数据Map */
            Map<String, Object> cpjlDataMap = new HashMap<String, Object>();

                /* 初始化各字段名称和表名 */
                String develop_sourceFieldName = "";
                String project_rateFieldName = "";
                String cpjlFieldName = "";
                String kfztFieldName = "";
                String mainTableName = "";
                String lcbFieldName = "";
                String lcbztFieldName = "";
                String zrrFieldName = "";
                String isLcbFieldName = "";
                String subTableName = "";


                /* 遍历字段配置，根据字段描述匹配对应的字段名称和表名 */
                for (FormFieldBean formFieldBean : yfxmda_fieldBeans) {
                    String fieldDesc = StrKit.str(formFieldBean.getDesc());
                    //用于查询项目经理资源池
                    if (productManager.equals(fieldDesc)) {
                        cpjlFieldName = StrKit.str(formFieldBean.getName());
                        mainTableName = formFieldBean.getOwnerTableName();
                    }
                    if (kfStatus.equals(fieldDesc)) {
                        kfztFieldName = StrKit.str(formFieldBean.getName());
                    }

                    //用于查询推品、设计、打样、制标资源池
                    if (lcbType.equals(fieldDesc)) {
                        lcbFieldName = formFieldBean.getName();
                        subTableName = formFieldBean.getOwnerTableName();
                    }
                    if (lcbStatus.equals(fieldDesc)) {
                        lcbztFieldName = formFieldBean.getName();
                    }
                    if (person_in_charge.equals(fieldDesc)) {
                        zrrFieldName = formFieldBean.getName();
                    }
                    if (develop_source.equals(fieldDesc)) {
                        develop_sourceFieldName = formFieldBean.getName();
                    }
                    if (project_rate.equals(fieldDesc)) {
                        project_rateFieldName = formFieldBean.getName();
                    }
                    if (isLcb.equals(fieldDesc)) {
                        isLcbFieldName = formFieldBean.getName();
                    }
                }

                /* 根据字段名称和表名构建查询SQL */
                /* 开发状态-关闭取消 */
                CtpEnumItem gbqxEnumItem = getEnumByCode("KFZT_GBQX");
                /* 里程碑-关闭取消 */
                CtpEnumItem lcb_gbqxEnumItem = getEnumByCode("LCBZT_QXGB");
                StringBuilder stb = new StringBuilder();
                stb.append("select ");
                if (!"".equals(develop_sourceFieldName) && !"".equals(project_rateFieldName)) {
                    stb.append(develop_sourceFieldName).append(", ").append(project_rateFieldName).append(", ");
                }
                if (!"".equals(cpjlFieldName) && !"".equals(mainTableName)) {
                    stb.append(cpjlFieldName).append(", ").append(kfztFieldName).append(" from ");
                    stb.append(mainTableName).append(" where ").append(kfztFieldName);
                    stb.append(" != '").append(gbqxEnumItem.getId()).append("'");
                }

                /* 执行查询，并根据查询结果进行数据处理 */
                List cpjlList = capDataListSqlHelpManager.selectDataList(stb.toString(), null);
                /* 处理产品经理的统计数据 */
                cpjlDataMap = cpjlData( cpjlList, develop_sourceFieldName, project_rateFieldName, cpjlFieldName, kfztFieldName, cpjlDataMap);

                /* 遍历里程碑类型，为每种类型构建并执行查询，处理统计数据 */
                for (MilestoneEnum milestoneEnum : MilestoneEnum.values()) {
                    /* 构建查询SQL */
                    String enumKey = milestoneEnum.getKey();
                    String enumValue = milestoneEnum.getValue();
                    CtpEnumItem ctpEnumItem = getEnumByCode(enumKey);
                    StringBuilder otherStb = new StringBuilder();
                    otherStb.append("select ");
                    if (!"".equals(develop_sourceFieldName) && !"".equals(project_rateFieldName)) {
                        otherStb.append(develop_sourceFieldName).append(", ").append(project_rateFieldName).append(", ");
                    }
                    if (!"".equals(lcbFieldName) && !"".equals(subTableName) && !"".equals(lcbztFieldName)) {
                        otherStb.append(zrrFieldName).append(", ").append(lcbFieldName).append(", ");
                        otherStb.append(lcbztFieldName).append(" from ").append(subTableName).append(" f1 ");
                        otherStb.append("left join ").append(mainTableName).append(" f on f1.formmain_id = f.id where ");
                        otherStb.append(lcbztFieldName).append(" != '").append(lcb_gbqxEnumItem.getId()).append("' and ");
                        otherStb.append(lcbFieldName).append(" ='").append(ctpEnumItem.getId()).append("' and ");
                        otherStb.append(isLcbFieldName).append(" = '").append(qxEnum_sfS.getId()).append("'");
                    }
                    log.info("查询资源池模块推品设计打样制标sql语句:" + otherStb.toString());

                    /* 执行查询，并处理统计数据 */
                    List otherList = capDataListSqlHelpManager.selectDataList(otherStb.toString(), null);
                    if (!otherList.isEmpty()) {
                        Map<String, Object> other_newDataMap = null;
                        if (resultDataMap.containsKey(enumValue)) {
                            other_newDataMap = (Map<String, Object>) resultDataMap.get(enumValue);
                        } else {
                            other_newDataMap = new HashMap<String, Object>();
                        }
                        Map<String, Object> newDataMap = otherData(develop_sourceFieldName,project_rateFieldName , otherList, zrrFieldName, lcbztFieldName, other_newDataMap);
                        resultDataMap.put(enumValue, newDataMap);
                    }
//                    log.info("数据信息:" + value + ":" + enumValue + ":" + JSON.toJSONString(resultDataMap));
                }
            //}
            /* 将产品经理和其他类型的统计数据添加到结果数据Map中 */
            resultDataMap.put("cpjl", cpjlDataMap);
            return resultDataMap;
        } catch (Exception e) {
            /* 捕获并记录查询过程中的异常 */
            log.error("资源池使用情况模块报错信息:", e);
            resultDataMap.put("code",500);
            resultDataMap.put("msg", e.getMessage());
            return resultDataMap;
        }
    }

    /**
     * 根据项目名称、开始时间和结束时间获取项目信息数据列表。
     *
     * @param projectName 项目名称
     * @param startTime   开始时间
     * @param endTime     结束时间
     * @return 项目信息数据列表
     * @throws BusinessException 业务异常
     */
    @Override
    public List<Map<String, Object>> getProjectInfoDataList(String projectName, String startTime, String endTime,String projectCode, String level, String status,String comeSource,String proManagerName,String cusManagerName, String productsManagerName) throws BusinessException {
        /* 获取系统属性中的项目相关字段描述 */


        /* 初始化需要的数据 */
        List<Map<String, Object>> resultDataList = new ArrayList<Map<String, Object>>();
        String tableName="";
        String source="";
        String proCode="";
        String proName="";
        String projectLevel="";
        String projectManager="";
        String customersManager="";
        String productsManager="";
        String developStatu="";
        String workNeedDate="";
        String percentageTpName="";
        String percentageSjName="";
        String percentageDyName="";
        String percentageZbName="";
        String personTp="";
        String personSj="";
        String personDy="";
        String personZb="";

        /*明细表字段*/
        String isLcb="";
        String lcb="";
        String planDate="";
        String trueDate="";
        /*明细表名*/
        String zjhTableName="";



        try {
            /* 初始化结果数据列表 */

            /*获取项目研发档案表中对应字段*/
            String yfdd_formCode = AppContext.getSystemProperty("kanban.yfxmda_formCode");
            FormBean formBean = cap4FormManager.getFormByFormCode(yfdd_formCode);
            if (formBean!=null){
                /* <!--研发项目来源-->*/
                /*<!--研发项目来源-->*/
                source=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_kfxmly")).getName();
                tableName=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_kfxmly")).getOwnerTableName();
                /*研发项目编码*/
                proCode=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_kfxmbm")).getName();
                /*研发项目名称*/
                proName=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_kfxmmc")).getName();
                /*项目级别*/
                projectLevel=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_xqpj")).getName();
                /*项目经理*/
                projectManager = formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_xmjl")).getName();
                /*客户经理*/
                customersManager=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_khjl")).getName();
                /*产品经理*/
                productsManager=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_cpjl")).getName();
                /*开发状态*/
                developStatu=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_fkzt")).getName();
                /*工作需求日期*/
                workNeedDate=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_yjjssj")).getName();
                /*推品完成百分比*/
                percentageTpName=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_tpbfb")).getName();
                /*设计完成百分比*/
                percentageSjName=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_sjbfb")).getName();
                /*打样完成百分比*/
                percentageDyName=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_dybfb")).getName();
                /*制标完成百分比*/
                percentageZbName=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_zybfb")).getName();
                /*推品负责人*/
                personTp=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_tpfzr")).getName();
                /*设计负责人*/
                personSj=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_sjfzr")).getName();
                /*打样负责人*/
                personDy=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_dyfzr")).getName();
                /*制标负责人*/
                personZb=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_zbfzr")).getName();
//                /*计划结束时间-推品子计划*/
//                tpPlanDate= formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_tpplanjssj")).getName();
//                /*计划结束时间-设计子计划*/
//                sjPlanDate= formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_sjplanjssj")).getName();
//                /*计划结束时间-打样子计划*/
//                dyPlanDate= formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_dyplanjssj")).getName();
//                /*计划结束时间-制标子计划*/
//                zbPlanDate=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_zbplanjssj")).getName();
//                /*实际结束时间-推品子计划*/
//                tpTrueDate=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_tpTurejssj")).getName();
//                /*实际结束时间-设计子计划*/
//                sjTrueDate= formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_sjTurejssj")).getName();
//                /*实际结束时间-打样子计划*/
//                dyTrueDate= formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_dyTurejssj")).getName();
//                /*实际结束时间-制标子计划*/
//                zbTrueDate= formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_zbTurejssj")).getName();
//                /*推品明细表名*/
//                tpTableName=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_tpplanjssj")).getOwnerTableName();
//                /*设计明细表名*/
//                sjTableName=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_sjplanjssj")).getOwnerTableName();
//                /*打样明细表名*/
//                dyTableName=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_dyplanjssj")).getOwnerTableName();
//                /*制标明细表名*/
//                zbTableName=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_zbplanjssj")).getOwnerTableName();

                /*是否里程碑*/
                isLcb=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_isLcb")).getName();
                /*里程碑*/
                lcb=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_lcb")).getName();
                /*计划开始时间*/
                planDate=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_zjhPlanjssj")).getName();
                /*实际完成时间*/
                trueDate=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_zjhTruejssj")).getName();
                zjhTableName=formBean.getFieldBeanByDisplay(AppContext.getSystemProperty("kanban.ipd_fieldCode_lcb")).getOwnerTableName();


                StringBuilder sql = new StringBuilder();
                sql.append("select id as id, ");

                /*当获取到的字段不为空时，拼接进入sql*/
                List<String> fields = new ArrayList<>();
                if (!"".equals(source)) {
                    fields.add(source);
                }
                if (!"".equals(proCode)) {
                    fields.add(proCode);
                }
                if (!"".equals(proName)) {
                    fields.add(proName);
                }
                if (!"".equals(projectLevel)) {
                    fields.add(projectLevel);
                }
                if (!"".equals(projectManager)) {
                    fields.add(projectManager);
                }
                if (!"".equals(customersManager)) {
                    fields.add(customersManager);
                }
                if (!"".equals(productsManager)) {
                    fields.add(productsManager);
                }
                if (!"".equals(developStatu)) {
                    fields.add(developStatu);
                }
                if (!"".equals(percentageTpName)) {
                    fields.add(percentageTpName);
                }
                if (!"".equals(percentageSjName)) {
                    fields.add(percentageSjName);
                }
                if (!"".equals(percentageDyName)) {
                    fields.add(percentageDyName);
                }
                if (!"".equals(percentageZbName)) {
                    fields.add(percentageZbName);
                }
                if (!"".equals(workNeedDate)) {
                    fields.add(workNeedDate);
                }
                if (!"".equals(personTp)) {
                    fields.add(personTp);
                }
                if (!"".equals(personSj)) {
                    fields.add(personSj);
                }
                if (!"".equals(personDy)) {
                    fields.add(personDy);
                }
                if (!"".equals(personZb)) {
                    fields.add(personZb);
                }

                // 将所有非空字段添加到 SQL 语句中
                for (int i = 0; i < fields.size(); i++) {
                    sql.append(fields.get(i));
                    if (i < fields.size() - 1) {
                        sql.append(", ");
                    }
                }
                //根据入参处理模糊查询，在sql品拼接条件
                sql.append(" from ").append(tableName).append(" where ");

                boolean firstCondition = true;
                int appendCount=0;

                if (!"".equals(projectName)) {
                    if (!firstCondition) {
                        sql.append(" and ");
                    }
                    sql.append(proName).append(" like '%").append(projectName).append("%'");
                    firstCondition = false;
                    appendCount++;
                }
                if (!"".equals(startTime) && !"".equals(endTime)) {
                    if (!firstCondition) {
                        sql.append(" and ");
                    }
                    sql.append(workNeedDate).append(" between '").append(startTime).append("' and '").append(endTime).append("'");
                    firstCondition = false;
                    appendCount++;
                }
                if (!"".equals(projectCode)) {
                    if (!firstCondition) {
                        sql.append(" and ");
                        appendCount++;
                    }
                    sql.append(proCode).append(" like '%").append(projectCode).append("%'");
                    firstCondition = false;
                    appendCount++;
                }
                if (!"".equals(level)) {
                    if (!firstCondition) {
                        sql.append(" and ");
                    }
                    sql.append(projectLevel).append(" like '%").append(level).append("%'");
                    firstCondition = false;
                    appendCount++;
                }
                if (!"".equals(status)) {
                    if (!firstCondition) {
                        sql.append(" and ");
                    }
                    sql.append(developStatu).append(" like '%").append(status).append("%'");
                    firstCondition = false;
                    appendCount++;
                }
                if (!"".equals(comeSource)) {
                    if (!firstCondition) {
                        sql.append(" and ");
                    }
                    sql.append(source).append(" like '%").append(comeSource).append("%'");
                    firstCondition = false;
                    appendCount++;
                }
                if (!"".equals(proManagerName)) {
                    if (!firstCondition) {
                        sql.append(" and ");
                    }
                    sql.append(projectManager).append(" like '%").append(proManagerName).append("%'");
                    firstCondition = false;
                    appendCount++;
                }
                if (!"".equals(cusManagerName)) {
                    if (!firstCondition) {
                        sql.append(" and ");
                    }
                    sql.append(customersManager).append(" like '%").append(cusManagerName).append("%'");
                    firstCondition = false;
                    appendCount++;
                }
                if (!"".equals(productsManagerName)) {
                    if (!firstCondition) {
                        sql.append(" and ");
                    }
                    sql.append(productsManager).append(" like '%").append(productsManagerName).append("%'");
                    appendCount++;
                }

                // 如果没有条件，则添加一个始终成立的条件
                if (appendCount==0) {
                    sql.append(" 1=1 ");
                }
                log.info("项目信息查询SQL： " + sql.toString());
                List dataList = capDataListSqlHelpManager.selectDataList(sql.toString(), null);
                int sort=0;
                /*查询结果不为空，进行数据处理*/
                if (!dataList.isEmpty()) {
                    for (int i = 0; i < dataList.size(); i++) {
                        sort += 1;
                        Map<String, Object> resultDataMap = new HashMap<String, Object>();
                        Map<String, Object> dataMap = (Map<String, Object>) dataList.get(i);
                        String masterId = StrKit.str(dataMap.get("id"));
                        String projectNameValue = StrKit.str(dataMap.get(proName));
                        /*档案表跳转url*/
                        /*获取跳转url参数*/
                        CAPFormDefinition capFormDefinition = capFormDefinitionManager.selectById(formBean.getId());
                        String appbindInfo = capFormDefinition.getAppbindInfo();
                        Map<String,Object> jsonObject = JSONObject.parseObject(appbindInfo,Map.class);
                        List<Map<String, Object>> formBindAuthList =  (List<Map<String, Object>>)jsonObject.get("formBindAuthList");
                        String tempId = StrKit.str(formBindAuthList.get(0).get("id"));
                        String url="/seeyon/cap4/businessTemplateController.do?method=formContent&type=browse&rightId=-2124232565598237106.-9073721612334249312_-225560122871887552.-3127089283143351434&moduleId="+masterId+"&formTemplateId="+tempId+"&viewConditionId=&columnId=8956722498566180148&moduleType=42&conditionIdDeal=&needUpdate=1&tplId=850010";
                        String projectCodeValue = StrKit.str(dataMap.get(proCode));
                        resultDataMap.put("projectCode", projectCodeValue);
                        /*根据开发状态值获取显示值*/
                        String kfStatuslValue = StrKit.str(dataMap.get(developStatu));
                        if (!"".equals(kfStatuslValue)) {
                            CtpEnumItem kfStatusEnum = enumManager.getCtpEnumItem(Long.parseLong(kfStatuslValue));
                            resultDataMap.put("kfStatus", kfStatusEnum.getShowvalue());
                            resultDataMap.put("kfStatusID",kfStatuslValue);
                        } else {
                            resultDataMap.put("kfStatus", "");
                            resultDataMap.put("kfStatusID", "");
                        }

                        /*根据开发来源值获取显示值*/
                        String proSource = StrKit.str(dataMap.get(source));
                        if (!"".equals(proSource)) {
                            CtpEnumItem proSourceEnum = enumManager.getCtpEnumItem(Long.parseLong(proSource));
                            resultDataMap.put("developmentSource", proSourceEnum.getShowvalue());
                        } else {
                            resultDataMap.put("developmentSource", "");
                        }
                        resultDataMap.put("url", url);
                        resultDataMap.put("sort", sort);
                        resultDataMap.put("projectName", projectNameValue);

                        /* 根据项目级别值获取显示值 */
                        String projectLevelValue = StrKit.str(dataMap.get(projectLevel));
                        if (!"".equals(projectLevelValue)) {
                            CtpEnumItem projectLevelEnum = enumManager.getCtpEnumItem(Long.parseLong(projectLevelValue));
                            resultDataMap.put("projectLevel", projectLevelEnum.getShowvalue());
                            resultDataMap.put("projectLevelID", projectLevelValue);
                        } else {
                            resultDataMap.put("projectLevel", "");
                            resultDataMap.put("projectLevelID", "");
                        }
                        /* 根据项目经理、客户经理和产品经理值获取名称 */
                        String projectManagerValue = StrKit.str(dataMap.get(projectManager));
                        if (!"".equals(projectManagerValue)) {
                            V3xOrgMember v3xOrgMember = orgManager.getMemberById(Long.parseLong(projectManagerValue));
                            resultDataMap.put("projectManager", v3xOrgMember.getName());
                            resultDataMap.put("projectManagerID", projectManagerValue);
                        } else {
                            resultDataMap.put("projectManager", "");
                            resultDataMap.put("projectManagerID", "");
                        }
                        /* 根据客户经理字段获取客户经理名称 */
                        String customerManagerValue = StrKit.str(dataMap.get(customersManager));
                        if (!"".equals(customerManagerValue)) {
                            V3xOrgMember v3xOrgMember = orgManager.getMemberById(Long.parseLong(customerManagerValue));
                            resultDataMap.put("customerManager", v3xOrgMember.getName());
                            resultDataMap.put("customerManagerID", customerManagerValue);
                        } else {
                            resultDataMap.put("customerManager", "");
                            resultDataMap.put("customerManagerID", "");
                        }

                        /* 根据产品经理字段获取产品经理名称 */
                        String productManagerValue = StrKit.str(dataMap.get(productsManager));
                        if (!"".equals(productManagerValue)) {
                            V3xOrgMember v3xOrgMember = orgManager.getMemberById(Long.parseLong(productManagerValue));
                            resultDataMap.put("productManager", v3xOrgMember.getName());
                            resultDataMap.put("productManagerID",productManagerValue);
                        } else {
                            resultDataMap.put("productManager", "");
                            resultDataMap.put("productManagerID", "");
                        }
                        /* 获取主要完成日期时间并添加到结果数据映射中 */
                        String mainQwwcDateTimeValue = StrKit.str(dataMap.get(workNeedDate));
                        resultDataMap.put("jjfaxqsj", mainQwwcDateTimeValue);

                        /* 根据推品负责人字段获取推品负责人名称 */
                        String personTpValue = StrKit.str(dataMap.get(personTp));
                        if (!"".equals(personTpValue)) {
                            V3xOrgMember v3xOrgMember = orgManager.getMemberById(Long.parseLong(personTpValue));
                            resultDataMap.put("personTp", v3xOrgMember.getName());
                        } else {
                            resultDataMap.put("personTp", "");
                        }


                        /* 根据设计负责人字段获取设计负责人名称 */
                        String personSjValue = StrKit.str(dataMap.get(personSj));
                        if (!"".equals(personSjValue)) {
                            V3xOrgMember v3xOrgMember = orgManager.getMemberById(Long.parseLong(personSjValue));
                            resultDataMap.put("personSj", v3xOrgMember.getName());
                        } else {
                            resultDataMap.put("personSj", "");
                        }

                        /* 根据推品负责人字段获取推品负责人名称 */
                        String personDyValue = StrKit.str(dataMap.get(personDy));
                        if (!"".equals(personDyValue)) {
                            V3xOrgMember v3xOrgMember = orgManager.getMemberById(Long.parseLong(personDyValue));
                            resultDataMap.put("personDy", v3xOrgMember.getName());
                        } else {
                            resultDataMap.put("personDy", "");
                        }

                        /* 根据推品负责人字段获取推品负责人名称 */
                        String personZbValue = StrKit.str(dataMap.get(personZb));
                        if (!"".equals(personZbValue)) {
                            V3xOrgMember v3xOrgMember = orgManager.getMemberById(Long.parseLong(personZbValue));
                            resultDataMap.put("personZb", v3xOrgMember.getName());
                        } else {
                            resultDataMap.put("personZb", "");
                        }


                        /* 获取百分比进度添加到结果数据映射中 */
                        /*推品百分比*/
                        String percentageTp = StrKit.str(dataMap.get(percentageTpName));
                        resultDataMap.put("percentageTp", percentageTp);
                        /*设计百分比*/
                        String percentageSj = StrKit.str(dataMap.get(percentageSjName));
                        resultDataMap.put("percentageSj", percentageSj);
                        /*打样百分比*/
                        String percentageDy = StrKit.str(dataMap.get(percentageDyName));
                        resultDataMap.put("percentageDy", percentageDy);
                        /*制标百分比*/
                        String percentageZb = StrKit.str(dataMap.get(percentageZbName));
                        resultDataMap.put("percentageZb", percentageZb);

                        /*获取四个明细表的计划结束时间，实际完成时间*/


                        /*明细表字段*/
//                        String isLcb="";
//                        String lcb="";
//                        String planDate="";
//                        String trueDate="";
                        /*明细表名*/
//                        String zjhTableName="";
                        /*处理是否历程和里程碑的枚举值*/
                        String tpEnumId="";
                        String sjEnumId="";
                        String dyEnumId="";
                        String zbEnumId="";
                        String sflcbEnumId="";

                        if (!"".equals(isLcb) && !"".equals(lcb) ){
                            tpEnumId=StrKit.str(enumManager.getItemByCode(AppContext.getSystemProperty("kanban.ipd_fieldCode_tpLcb")).getId());
                            sjEnumId= StrKit.str(enumManager.getItemByCode(AppContext.getSystemProperty("kanban.ipd_fieldCode_sjLcb")).getId());
                            dyEnumId=StrKit.str(enumManager.getItemByCode(AppContext.getSystemProperty("kanban.ipd_fieldCode_dyLcb")).getId());
                            zbEnumId=StrKit.str(enumManager.getItemByCode(AppContext.getSystemProperty("kanban.ipd_fieldCode_zbLcb")).getId());
                            sflcbEnumId=StrKit.str(enumManager.getItemByCode("Y").getId());

                        }

                        /*推品子计划*/
                        if (!"".equals(isLcb) && !"".equals(lcb) ){
                            /*拼接sql查询数据*/
                            String tpSQL= "select "+planDate+" as plandate , "+trueDate+" as turedate from "+zjhTableName+" where formmain_id = '"+masterId+"' and "+isLcb+" = '"+sflcbEnumId+"' and "+lcb+"= '"+tpEnumId+"'";
                            log.info("推品子计划查询SQL： "+tpSQL);
                            List data = capDataListSqlHelpManager.selectDataList(tpSQL, null);
                            log.info("推品子计划查询datasize： "+data.size());
                            if (data.size()>0){
                                Map<String, Object> tpMap = (Map<String, Object>) data.get(0);
                                String tpPlanDateValue = StrKit.str(tpMap.get("plandate"));
                                String tpTrueDateValue = StrKit.str(tpMap.get("turedate"));
                                resultDataMap.put("tpPlanDate", tpPlanDateValue);
                                resultDataMap.put("tpTrueDate", tpTrueDateValue);
                            }else{
                                resultDataMap.put("tpPlanDate", "");
                                resultDataMap.put("tpTrueDate", "");
                            }
                        }else {
                            resultDataMap.put("tpPlanDate", "");
                            resultDataMap.put("tpTrueDate", "");
                        }

                        /*设计子计划*/
                        if (!"".equals(isLcb) && !"".equals(lcb) ){
                            /*拼接sql查询数据*/
                            String sjSQL= "select "+planDate+" as plandate , "+trueDate+" as turedate from "+zjhTableName+" where formmain_id = '"+masterId+"' and "+isLcb+" = '"+sflcbEnumId+"' and "+lcb+" = '"+sjEnumId+"'";
                            log.info("设计子计划查询SQL： "+sjSQL);
                            List data = capDataListSqlHelpManager.selectDataList(sjSQL, null);
                            log.info("设计子计划查询data.size： "+data.size());
                            /*数据不为空进行数据处理*/
                            if(data.size()>0){
                                Map<String, Object> sjMap = (Map<String, Object>) data.get(0);
                                String sjPlanDateValue = StrKit.str(sjMap.get("plandate"));
                                String sjTrueDateValue = StrKit.str(sjMap.get("turedate"));
                                resultDataMap.put("sjPlanDate", sjPlanDateValue);
                                resultDataMap.put("sjTrueDate", sjTrueDateValue);
                            } else {
                                resultDataMap.put("sjPlanDate", "");
                                resultDataMap.put("sjTrueDate", "");
                            }
                        }else {
                            resultDataMap.put("sjPlanDate", "");
                            resultDataMap.put("sjTrueDate", "");
                        }

                        /*打样子计划*/
                        if (!"".equals(isLcb) && !"".equals(lcb)){
                            /*拼接sql查询数据*/
                            String dySQL= "select "+planDate+" as plandate , "+trueDate+" as turedate from "+zjhTableName+" where formmain_id = '"+masterId+"' and "+isLcb+" = '"+sflcbEnumId+"' and "+lcb+" = '"+dyEnumId+"'";
                            log.info("打样子计划查询SQL： "+dySQL);
                            List data = capDataListSqlHelpManager.selectDataList(dySQL, null);
                            log.info("打样子计划查询data.size： "+data.size());
                            if(data.size()>0){
                                Map<String, Object> dyMap = (Map<String, Object>) data.get(0);
                                String dyPlanDateValue = StrKit.str(dyMap.get("plandate"));
                                String dyTrueDateValue = StrKit.str(dyMap.get("turedate"));
                                resultDataMap.put("dyPlanDate", dyPlanDateValue);
                                resultDataMap.put("dyTrueDate", dyTrueDateValue);
                            }else {
                                resultDataMap.put("dyPlanDate", "");
                                resultDataMap.put("dyTrueDate", "");
                            }
                        }else {
                            resultDataMap.put("dyPlanDate", "");
                            resultDataMap.put("dyTrueDate", "");
                        }

                        /*制表子计划*/
                        if (!"".equals(isLcb) && !"".equals(lcb)){
                            /*拼接sql查询数据*/
                            String zbSQL= "select "+planDate+" as plandate , "+trueDate+" as turedate from "+zjhTableName+" where formmain_id = '"+masterId+"' and "+isLcb+" = '"+sflcbEnumId+"' and "+lcb+" = '"+zbEnumId+"'";
                            log.info("制表子查询SQL： "+zbSQL);
                            List data = capDataListSqlHelpManager.selectDataList(zbSQL, null);
                            log.info("制表子查询data.size()： "+data.size());
                            if (data.size()>0){
                                Map<String, Object> zbMap = (Map<String, Object>) data.get(0);
                                String zbPlanDateValue = StrKit.str(zbMap.get("plandate"));
                                String zbTrueDateValue = StrKit.str(zbMap.get("turedate"));
                                resultDataMap.put("zbPlanDate", zbPlanDateValue);
                                resultDataMap.put("zbTrueDate", zbTrueDateValue);
                            }else {
                                resultDataMap.put("zbPlanDate", "");
                                resultDataMap.put("zbTrueDate", "");
                            }
                        }else {
                            resultDataMap.put("zbPlanDate", "");
                            resultDataMap.put("zbTrueDate", "");
                        }

                        /* 将结果数据映射添加到结果数据列表中 */
                        resultDataList.add(resultDataMap);
                    }
                }

            }

        }catch (Exception e){
            log.error("获取项目信息报错异常:", e);
        }



        return resultDataList;
    }

    @Override
    public Map<String, Object> getyjxx() throws BusinessException, SQLException {
        Map<String,Object> resMap=new HashMap<>();

        String yjzb_zblq = AppContext.getSystemProperty("kanban.yjzb_zblq");
        String yjzb_zbcq = AppContext.getSystemProperty("kanban.yjzb_zbcq");
        String yjzb_dylq = AppContext.getSystemProperty("kanban.yjzb_dylq");
        String yjzb_dycq = AppContext.getSystemProperty("kanban.yjzb_dycq");
        String yjzb_sjlq = AppContext.getSystemProperty("kanban.yjzb_sjlq");
        String yjzb_sjcq = AppContext.getSystemProperty("kanban.yjzb_sjcq");
        String yjzb_tplq = AppContext.getSystemProperty("kanban.yjzb_tplq");
        String yjzb_tpcq = AppContext.getSystemProperty("kanban.yjzb_tpcq");
        String yjzb_xmlq = AppContext.getSystemProperty("kanban.yjzb_xmlq");
        String yjzb_xmcq = AppContext.getSystemProperty("kanban.yjzb_xmcq");

        Map<String,Object> xmMap=new HashMap<>();
        xmMap.put("cqNum",getXmyjCount("1").get("num"));
        xmMap.put("lqNum",getXmyjCount("2").get("num"));
        xmMap.put("cqUrl",FormCap4Kit.getBbAddres(yjzb_xmcq));
        xmMap.put("lqUrl",FormCap4Kit.getBbAddres(yjzb_xmlq));

        Map<String,Object> tpMap=new HashMap<>();
        tpMap.put("cqNum",getOtherYjCount("1","1").get("num"));
        tpMap.put("lqNum",getOtherYjCount("1","2").get("num"));
        tpMap.put("cqUrl",FormCap4Kit.getBbAddres(yjzb_tpcq));
        tpMap.put("lqUrl",FormCap4Kit.getBbAddres(yjzb_tplq));

        Map<String,Object> sjMap=new HashMap<>();
        sjMap.put("cqNum",getOtherYjCount("2","1").get("num"));
        sjMap.put("lqNum",getOtherYjCount("2","2").get("num"));
        sjMap.put("cqUrl",FormCap4Kit.getBbAddres(yjzb_sjcq));
        sjMap.put("lqUrl",FormCap4Kit.getBbAddres(yjzb_sjlq));

        Map<String,Object> dyMap=new HashMap<>();
        dyMap.put("cqNum",getOtherYjCount("3","1").get("num"));
        dyMap.put("lqNum",getOtherYjCount("3","2").get("num"));
        dyMap.put("cqUrl",FormCap4Kit.getBbAddres(yjzb_dycq));
        dyMap.put("lqUrl",FormCap4Kit.getBbAddres(yjzb_dylq));

        Map<String,Object> zbMap=new HashMap<>();
        zbMap.put("cqNum",getOtherYjCount("4","1").get("num"));
        zbMap.put("lqNum",getOtherYjCount("4","2").get("num"));
        zbMap.put("cqUrl",FormCap4Kit.getBbAddres(yjzb_zbcq));
        zbMap.put("lqUrl",FormCap4Kit.getBbAddres(yjzb_zblq));

        resMap.put("xm",xmMap);
        resMap.put("tp",tpMap);
        resMap.put("sj",sjMap);
        resMap.put("dy",dyMap);
        resMap.put("zb",zbMap);

        return resMap;
//        map.put("projectCq",getXmyjCount("1").get("num"));
//        map.put("projectLq",getXmyjCount("2").get("num"));
//        map.put("tpCq",getOtherYjCount("1","1").get("num"));
//        map.put("tpLq",getOtherYjCount("1","2").get("num"));
//        map.put("sjCq",getOtherYjCount("2","1").get("num"));
//        map.put("sjLq",getOtherYjCount("2","2").get("num"));
//        map.put("dyCq",getOtherYjCount("3","1").get("num"));
//        map.put("dyLq",getOtherYjCount("3","2").get("num"));
//        map.put("zbCq",getOtherYjCount("4","1").get("num"));
//        map.put("zbLq",getOtherYjCount("4","2").get("num"));
    }

    /**
     *
     * @param type
     * @return
     * @throws BusinessException
     * @throws SQLException
     */
    public Map<String, Object> getXmyjCount(String type) throws BusinessException, SQLException {
        // 获取当前日期
        Date date=new Date();
        // 创建一个日期时间格式器
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 格式化当前日期时间为字符串


        String code = AppContext.getSystemProperty("kanban.yfxmda_formCode");
        String kfzt_ywc = AppContext.getSystemProperty("kanban.kfzt_ywc");
        CtpEnumItem qxEnum_ywc = FormCap4Kit.getEnumByCode(kfzt_ywc);
        String kfzt_gb = AppContext.getSystemProperty("kanban.kfzt_gb");
        CtpEnumItem qxEnum_gb = FormCap4Kit.getEnumByCode(kfzt_gb);
        String kfStatus = AppContext.getSystemProperty("kanban.kfStatus");

        String lcbSubJdqk = AppContext.getSystemProperty("kanban.lcbSubJdqk");
        String lcbSubLq = AppContext.getSystemProperty("kanban.lcbSubLq");
        CtpEnumItem qxEnum_lcbSubLq = FormCap4Kit.getEnumByCode(lcbSubLq);
        String lcbSubCq = AppContext.getSystemProperty("kanban.lcbSubCq");
        CtpEnumItem qxEnum_lcbSubCq = FormCap4Kit.getEnumByCode(lcbSubCq);

        //获取对应表单
        FormBean formBean = cap4FormManager.getFormByFormCode(code);
        List<FormFieldBean> formFieldBeans = formBean.getMasterTableBean().getFields();
        StringBuilder stb = new StringBuilder();
        stb.append("select count(1) as num");
        String kfStatusFieldName = "";

        String lcbSubJdqkFieldName = "";
        for (FormFieldBean formFieldBean : formFieldBeans) {
            String fieldDesc = StrKit.str(formFieldBean.getDesc().trim());
            if (kfStatus.equals(fieldDesc)) {
                kfStatusFieldName = formFieldBean.getName();
            }
            if (lcbSubJdqk.equals(fieldDesc)){
                lcbSubJdqkFieldName = formFieldBean.getName();
            }
            if (!"".equals(fieldDesc)) {
                String fieldName = formFieldBean.getName();
//                stb.append(fieldName).append(",");
            }
        }
        /* 删除最后一个逗号，完成SQL查询语句的构建 */
        String str = stb.toString();
        String tableName = formBean.getMasterTableBean().getTableName();
        String newStr="";
        if (type.equals("1")){
            //超期
             newStr = str + " from " + tableName+" where "+kfStatusFieldName+" != '"+qxEnum_ywc.getId()+"' and "+kfStatusFieldName+" != '"+qxEnum_gb.getId()+
                 "' and "+lcbSubJdqkFieldName+"= '" +qxEnum_lcbSubCq.getId()+"'";
            log.info("研发项目档案-----超期sql语句：" + newStr);
        }else{
            //临期
            newStr = str + " from " + tableName+" where "+kfStatusFieldName+" != '"+qxEnum_ywc.getId()+"' and "+kfStatusFieldName+" != '"+qxEnum_gb.getId()
                +"' and "+lcbSubJdqkFieldName+"= '" +qxEnum_lcbSubLq.getId()+"'";
            log.info("研发项目档案-----临期sql语句：" + newStr);
        }
        /* 执行SQL查询 */
        List<Map<String, Object>> dataList = capDataListSqlHelpManager.selectDataList(newStr, null);
        log.info("采购订单档案信息-------" + JSON.toJSONString(dataList));
        return dataList.get(0);
    }

    /**
     *
     * @param type
     * @return
     * @throws BusinessException
     * @throws SQLException
     */
    public Map<String, Object> getOtherYjCount(String type,String status) throws BusinessException, SQLException {
        String code = AppContext.getSystemProperty("kanban.yfxmda_formCode");


        String lcb_tp = AppContext.getSystemProperty("kanban.lcbTp");
        CtpEnumItem qxEnum_tp = FormCap4Kit.getEnumByCode(lcb_tp);
        String lcb_sj = AppContext.getSystemProperty("kanban.lcbSj");
        CtpEnumItem qxEnum_sj = FormCap4Kit.getEnumByCode(lcb_sj);
        String lcb_dy = AppContext.getSystemProperty("kanban.lcbDy");
        CtpEnumItem qxEnum_dy = FormCap4Kit.getEnumByCode(lcb_dy);
        String lcb_zb = AppContext.getSystemProperty("kanban.lcbZb");
        CtpEnumItem qxEnum_zb = FormCap4Kit.getEnumByCode(lcb_zb);
        String lcbjhztYwc = AppContext.getSystemProperty("kanban.lcbjhztYwc");
        CtpEnumItem qxEnum_ywc = FormCap4Kit.getEnumByCode(lcbjhztYwc);
        String lcbjhztQx = AppContext.getSystemProperty("kanban.lcbjhztQx");
        CtpEnumItem qxEnum_qx = FormCap4Kit.getEnumByCode(lcbjhztQx);
        String lcbSubJdqk = AppContext.getSystemProperty("kanban.lcbSubJdqk");
        String lcbSubLq = AppContext.getSystemProperty("kanban.lcbSubLq");
        CtpEnumItem qxEnum_lcbSubLq = FormCap4Kit.getEnumByCode(lcbSubLq);
        String lcbSubCq = AppContext.getSystemProperty("kanban.lcbSubCq");
        CtpEnumItem qxEnum_lcbSubCq = FormCap4Kit.getEnumByCode(lcbSubCq);

        String kfzt_ywc = AppContext.getSystemProperty("kanban.kfzt_ywc");
        CtpEnumItem enum_ywc = FormCap4Kit.getEnumByCode(kfzt_ywc);
        String kfzt_gb = AppContext.getSystemProperty("kanban.kfzt_gb");
        CtpEnumItem enum_gb = FormCap4Kit.getEnumByCode(kfzt_gb);

        String mx_kfxmzt = "mx_kfxmzt";

        String sfS = AppContext.getSystemProperty("kanban.sfS");
        CtpEnumItem qxEnum_sfS = FormCap4Kit.getEnumByCode(sfS);


        String lcb_sf = AppContext.getSystemProperty("kanban.lcb_sf");
        String lcbType = AppContext.getSystemProperty("kanban.lcbType");

        String lcbStatus = AppContext.getSystemProperty("kanban.lcbStatus");


        //获取对应表单
        FormBean formBean = cap4FormManager.getFormByFormCode(code);
        List<FormFieldBean> formFieldBeans = formBean.getAllFieldBeans();
        StringBuilder stb = new StringBuilder();
        stb.append("select count(1) as num");

        String lcb_sfFieldName = "";
        String lcbTypeFieldName = "";
        String lcbSubJdqkFieldName = "";
        String lcbStatusFieldName = "";
        String kfztFieldName = "";
        for (FormFieldBean formFieldBean : formFieldBeans) {
            String fieldDesc = StrKit.str(formFieldBean.getDesc().trim());
            if (lcb_sf.equals(fieldDesc)) {
                lcb_sfFieldName = formFieldBean.getName();
            }

            if (lcbType.equals(fieldDesc)) {
                lcbTypeFieldName = formFieldBean.getName();
            }
            if (lcbSubJdqk.equals(fieldDesc)) {
                lcbSubJdqkFieldName = formFieldBean.getName();
            }

            if (lcbStatus.equals(fieldDesc)) {
                lcbStatusFieldName = formFieldBean.getName();
            }
            if (mx_kfxmzt.equals(fieldDesc)){
                kfztFieldName = formFieldBean.getName();
            }
            if (!"".equals(fieldDesc)) {
                String fieldName = formFieldBean.getName();
                //                stb.append(fieldName).append(",");
            }
        }
        /* 删除最后一个逗号，完成SQL查询语句的构建 */
        String str = stb.toString();
        List<FormTableBean> subTableBean = formBean.getSubTableBean();
        String newStr = "";
        for (int i = 0; i < subTableBean.size(); i++) {
            String tableName = "";
            if ("项目主计划".equals(subTableBean.get(i).getDisplay())) {
                tableName = subTableBean.get(i).getTableName();
                if (!tableName.isEmpty()) {
                    newStr = str + " from " + tableName;
                    log.info("项目主计划明细表-----sql语句：" + newStr);
                }
            }
        }
        newStr= newStr+" where "+lcb_sfFieldName+"= '"+qxEnum_sfS.getId()+
                "' and "+lcbStatusFieldName+" != '"+qxEnum_ywc.getId()+
                "' and "+lcbStatusFieldName+" != '"+qxEnum_qx.getId()+"'"
                +" and "+kfztFieldName +" not in "+ "('"+enum_ywc.getId()+"','"+enum_gb.getId()+"')";
        if (type.equals("1")){
            //推品
            //超期
            if(status.equals("1")) {
                newStr = newStr + " and " + lcbTypeFieldName + "= '" + qxEnum_tp.getId() + "' and " + lcbSubJdqkFieldName + " = '" + qxEnum_lcbSubCq.getId()+"'";
                log.info("研发项目档案-----推品超期sql语句：" + newStr);
            }else {
                //临期
                newStr = newStr + " and " + lcbTypeFieldName + "= '" + qxEnum_tp.getId() + "' and " + lcbSubJdqkFieldName + " = '" + qxEnum_lcbSubLq.getId()+"'";
                log.info("研发项目档案-----推品临期sql语句：" + newStr);
            }
        }else if(type.equals("2")){
            //设计
            //超期
            if(status.equals("1")) {
                newStr = newStr + " and " + lcbTypeFieldName + "= '" + qxEnum_sj.getId() + "' and " + lcbSubJdqkFieldName+ " = '" + qxEnum_lcbSubCq.getId()+"'";
                log.info("研发项目档案-----设计超期sql语句：" + newStr);
            }else {
                //临期
                newStr = newStr + " and " + lcbTypeFieldName + "= '" + qxEnum_sj.getId() + "' and " + lcbSubJdqkFieldName + " = '" + qxEnum_lcbSubLq.getId()+"'";
                log.info("研发项目档案-----设计临期sql语句：" + newStr);
            }

        }else if (type.equals("3")){
            //打样
            //超期
            if(status.equals("1")) {
                newStr = newStr + " and " + lcbTypeFieldName + "= '" + qxEnum_dy.getId() + "' and " + lcbSubJdqkFieldName + " = '" + qxEnum_lcbSubCq.getId()+"'";
                log.info("研发项目档案-----打样超期sql语句：" + newStr);
            }else {
                //临期
                newStr = newStr + " and " + lcbTypeFieldName + "= '" + qxEnum_dy.getId() + "' and " + lcbSubJdqkFieldName + " = '" + qxEnum_lcbSubLq.getId()+"'";
                log.info("研发项目档案-----打样临期sql语句：" + newStr);
            }

        }else{
            //制标
            //超期
            if(status.equals("1")) {
                newStr = newStr + " and " + lcbTypeFieldName + "= '" + qxEnum_zb.getId() + "' and " + lcbSubJdqkFieldName + " = '" + qxEnum_lcbSubCq.getId()+"'";
                log.info("研发项目档案-----制标超期期sql语句：" + newStr);
            }else {
                //临期
                newStr = newStr + " and " + lcbTypeFieldName + "= '" + qxEnum_zb.getId() + "' and " + lcbSubJdqkFieldName + " = '" + qxEnum_lcbSubLq.getId()+"'";
                log.info("研发项目档案-----制标临期sql语句：" + newStr);
            }
        }
        /* 执行SQL查询 */
        List<Map<String, Object>> dataList = capDataListSqlHelpManager.selectDataList(newStr, null);
        log.info("项目档案信息-------" + JSON.toJSONString(dataList));
        return dataList.get(0);
    }





    /**
     * 根据传入的列表和字段名称，统计处理结果数据。
     *
     * @param cpjlList 处理结果列表
     * @param develop_sourceFieldName 处理结果列表中，开发来源的字段名称。
     * @param project_rateFieldName 处理结果列表中，项目星级的字段名称。
     * @param cpjlFieldName 处理结果列表中，项目经理ID的字段名称。
     * @param kfztFieldName 处理结果列表中，处理状态的字段名称。
     * @param cpjlDataMap 用于存储统计结果的映射表。
     * @return 统计后的数据映射表
     * @throws BusinessException 业务异常
     */
    private Map<String, Object> cpjlData(List cpjlList, String develop_sourceFieldName,String project_rateFieldName, String cpjlFieldName, String kfztFieldName, Map<String, Object> cpjlDataMap) throws BusinessException {
        // 如果列表不为空，遍历处理结果列表
        if (!cpjlList.isEmpty()) {
            for (int i = 0; i < cpjlList.size(); i++) {
                // 初始化成员名称
                String memberName = "";
                // 获取当前处理结果的映射表
                Map<String, Object> cpjlMap = (Map<String, Object>) cpjlList.get(i);
                String develop_sourceValue = "";
                String project_rateValue = "";
                if (!"".equals(develop_sourceFieldName) && !"".equals(project_rateFieldName)) {
                    develop_sourceValue = StrKit.str(cpjlMap.get(develop_sourceFieldName));
                    project_rateValue = StrKit.str(cpjlMap.get(project_rateFieldName));
                }

                // 获取开发来源，并判断是否为空
                String develop_source_enumItemCode = "";
                String project_rate_enumItemCode = "";
                if (!"".equals(develop_sourceValue) ) {
                    // 根据开发来源id，获取枚举项，获取开发来源编码
                    develop_source_enumItemCode = StrKit.str(enumManager.getCtpEnumItem(Long.parseLong(develop_sourceValue)).getEnumItemCode());
                }

                if (!"".equals(project_rateValue) ) {
                    // 根据项目星级id，获取枚举项,并获取项目星级编码
                    project_rate_enumItemCode = StrKit.str(enumManager.getCtpEnumItem(Long.parseLong(project_rateValue)).getEnumItemCode());
                }


                // 获取处理人ID，并判断是否为空
                String cpjl = StrKit.str(cpjlMap.get(cpjlFieldName));
                if (!"".equals(cpjl)) {
                    // 根据处理人ID获取成员信息
                    V3xOrgMember v3xOrgMember = orgManager.getMemberById(Long.parseLong(cpjl));
                    // 获取成员名称
                    memberName = v3xOrgMember.getName();
                } else {
                    // 如果处理人ID为空，跳过当前循环
                    continue;
                }

                // 获取处理状态，并判断是否为空
                String kfzt = StrKit.str(cpjlMap.get(kfztFieldName));
                String enumItemCode = "";
                if (!"".equals(kfzt)) {
                    // 根据处理状态ID获取处理状态枚举项
                    CtpEnumItem lcbStatusEnum = enumManager.getCtpEnumItem(Long.parseLong(kfzt));
                    // 获取处理状态编码
                    enumItemCode = StrKit.str(lcbStatusEnum.getEnumItemCode());
                }

                // 如果当前成员名称在统计结果映射表中不存在，添加新的统计项
                if (!cpjlDataMap.containsKey(memberName)) {
                    Map<String, Object> cpjlNumMap = new HashMap<String, Object>();
                    cpjlNumMap.put("url", "");
                    cpjlNumMap.put("sumNum", 1);
                    //线索、机会点、自研、双十项目、非双十项目
                    cpjlNumMap.put("xswwcNum", 0);
                    cpjlNumMap.put("jhwwcNum", 0);
                    cpjlNumMap.put("zywwcNum", 0);
                    cpjlNumMap.put("sswwcNum", 0);
                    cpjlNumMap.put("fsswwcNum", 0);

                    if ("KFZT_YWC".equals(enumItemCode)) {
                        cpjlNumMap.put("ywcNum", 1);
                        cpjlNumMap.put("wwcNum", 0);
                    } else {
                        cpjlNumMap.put("ywcNum", 0);
                        cpjlNumMap.put("wwcNum", 1);
                        //  线索
                        if ("kfly_xs".equals(develop_source_enumItemCode)){
                            cpjlNumMap.put("xswwcNum", 1);
                        }
                        //  机会点
                        if ("kfly_jh".equals(develop_source_enumItemCode)){
                            cpjlNumMap.put("jhwwcNum", 1);
                        }
                        //  自研
                        if ("kfly_zy".equals(develop_source_enumItemCode)){
                            cpjlNumMap.put("zywwcNum", 1);
                        }
                        //  定制
                        if ("kfly_dz".equals(develop_source_enumItemCode)){

                            if (!"lx4_4".equals(project_rate_enumItemCode) && !"lx5_5".equals(project_rate_enumItemCode)){
                                //非双十
                                cpjlNumMap.put("fsswwcNum", 1);
                            }else{
                                //双十
                                cpjlNumMap.put("sswwcNum", 1);
                            }
                        }
                    }

                    cpjlDataMap.put(memberName, cpjlNumMap);
                } else {
                    // 如果当前成员名称在统计结果映射表中已存在，更新相应统计项
                    Map<String, Object> tempMap = (Map<String, Object>) cpjlDataMap.get(memberName);
                    int sumNum_new = Integer.parseInt(StrKit.str(tempMap.get("sumNum"))) + 1;
                    int ywcNum_new = 0;
                    int wwcNum_new = 0;
                    int xswwcNum_new = Integer.parseInt(StrKit.str(tempMap.get("xswwcNum")));
                    int jhwwcNum_new = Integer.parseInt(StrKit.str(tempMap.get("jhwwcNum")));
                    int zywwcNum_new = Integer.parseInt(StrKit.str(tempMap.get("zywwcNum")));
                    int fsswwcNum_new = Integer.parseInt(StrKit.str(tempMap.get("fsswwcNum")));
                    int sswwcNum_new = Integer.parseInt(StrKit.str(tempMap.get("sswwcNum")));
                    if ("KFZT_YWC".equals(enumItemCode)) {
                        ywcNum_new = Integer.parseInt(StrKit.str(tempMap.get("ywcNum"))) + 1;
                        wwcNum_new = Integer.parseInt(StrKit.str(tempMap.get("wwcNum")));
                    } else {
                        ywcNum_new = Integer.parseInt(StrKit.str(tempMap.get("ywcNum")));
                        wwcNum_new = Integer.parseInt(StrKit.str(tempMap.get("wwcNum"))) + 1;

                        //  线索
                        if ("kfly_xs".equals(develop_source_enumItemCode)){
                            xswwcNum_new += 1;
                        }
                        //  机会点
                        if ("kfly_jh".equals(develop_source_enumItemCode)){
                            jhwwcNum_new += 1;
                        }
                        //  自研
                        if ("kfly_zy".equals(develop_source_enumItemCode)){
                            zywwcNum_new += 1;
                        }
                        //  定制
                        if ("kfly_dz".equals(develop_source_enumItemCode)){

                            if ("lx4_4".equals(project_rate_enumItemCode) || "lx5_5".equals(project_rate_enumItemCode)){
                                //双十
                                sswwcNum_new += 1;

                            }else{
                                //非双十
                                fsswwcNum_new += 1;
                            }
                        }
                    }
                    cpjlDataMap.remove(memberName);
                    Map<String, Object> cpjlNumMap = new HashMap<String, Object>();
                    cpjlNumMap.put("url", "");
                    cpjlNumMap.put("sumNum", sumNum_new);
                    cpjlNumMap.put("ywcNum", ywcNum_new);
                    cpjlNumMap.put("wwcNum", wwcNum_new);
                    cpjlNumMap.put("xswwcNum", xswwcNum_new);
                    cpjlNumMap.put("jhwwcNum", jhwwcNum_new);
                    cpjlNumMap.put("zywwcNum", zywwcNum_new);
                    cpjlNumMap.put("fsswwcNum", fsswwcNum_new);
                    cpjlNumMap.put("sswwcNum", sswwcNum_new);

                    cpjlDataMap.put(memberName, cpjlNumMap);
                }
            }
        }
        // 返回统计后的数据映射表
        return cpjlDataMap;
    }


    /**
     * 根据指定的字段名称，处理其他列表数据，统计每个责任人的已完成和未完成任务数量。
     *
     * @param otherList      其他数据列表，包含待处理的数据项。
     * @param zrrFieldName   责任人字段名称，用于获取数据项中的责任人信息。
     * @param lcbztFieldName 任务状态字段名称，用于获取数据项中的任务状态信息。
     * @param otherDataMap   用于存储处理后的数据，键为责任人名称，值为包含完成和未完成任务数量的映射。
     * @return 经过处理的其他数据映射。
     * @throws BusinessException 如果处理过程中出现业务错误。
     */
    /**
     *
     * @param develop_sourceFieldName
     * @param project_rateFieldName
     * @param otherList
     * @param zrrFieldName
     * @param lcbztFieldName
     * @param otherDataMap
     * @return
     * @throws BusinessException
     */
    private Map<String, Object> otherData(String develop_sourceFieldName, String project_rateFieldName,List otherList,  String zrrFieldName, String lcbztFieldName, Map<String, Object> otherDataMap) throws BusinessException {

        // 如果其他列表不为空，则遍历处理每个数据项
        if (!otherList.isEmpty()) {
            for (int i = 0; i < otherList.size(); i++) {
                // 用于存储责任人的名称
                String memberName = "";
                // 从列表中获取当前的数据项
                Map<String, Object> otherMap = (Map<String, Object>) otherList.get(i);
                String develop_sourceValue = "";
                String project_rateValue = "";
                if (!"".equals(develop_sourceFieldName) && !"".equals(project_rateFieldName)) {
                    develop_sourceValue = StrKit.str(otherMap.get(develop_sourceFieldName));
                    project_rateValue = StrKit.str(otherMap.get(project_rateFieldName));
                }

                // 获取开发来源，并判断是否为空
                String develop_source_enumItemCode = "";
                String project_rate_enumItemCode = "";
                if (!"".equals(develop_sourceValue) ) {
                    // 根据开发来源id，获取枚举项，获取开发来源编码
                    develop_source_enumItemCode = StrKit.str(enumManager.getCtpEnumItem(Long.parseLong(develop_sourceValue)).getEnumItemCode());
                }

                if (!"".equals(project_rateValue) ) {
                    // 根据项目星级id，获取枚举项,并获取项目星级编码
                    project_rate_enumItemCode = StrKit.str(enumManager.getCtpEnumItem(Long.parseLong(project_rateValue)).getEnumItemCode());
                }
                // 获取责任人ID，并根据ID获取责任人的名称
                String zrr = StrKit.str(otherMap.get(zrrFieldName));
                if (!"".equals(zrr)) {
                    V3xOrgMember v3xOrgMember = orgManager.getMemberById(Long.parseLong(zrr));
                    memberName = v3xOrgMember.getName();
                } else {
                    // 如果责任人ID为空，则跳过当前数据项的处理
                    continue;
                }
                // 获取任务状态，并根据状态更新完成或未完成任务的数量
                String lcbzt = StrKit.str(otherMap.get(lcbztFieldName));
                String enumItemCode = "";
                if (!"".equals(lcbzt)) {
                    CtpEnumItem lcbStatusEnum = enumManager.getCtpEnumItem(Long.parseLong(lcbzt));
                    enumItemCode = StrKit.str(lcbStatusEnum.getEnumItemCode());
                }

                // 如果当前责任人尚未在otherDataMap中出现，则初始化其任务数量并添加到map中
                if (!otherDataMap.containsKey(memberName)) {
                    Map<String, Object> otherNumMap = new HashMap<String, Object>();
                    otherNumMap.put("url", "");
                    otherNumMap.put("sumNum", 1);
                    //线索、机会点、自研、双十项目、非双十项目
                    otherNumMap.put("xswwcNum", 0);
                    otherNumMap.put("jhwwcNum", 0);
                    otherNumMap.put("zywwcNum", 0);
                    otherNumMap.put("sswwcNum", 0);
                    otherNumMap.put("fsswwcNum", 0);
                    if ("LCBZT_YWC".equals(enumItemCode)) {
                        otherNumMap.put("ywcNum", 1);
                        otherNumMap.put("wwcNum", 0);
                    } else {
                        otherNumMap.put("ywcNum", 0);
                        otherNumMap.put("wwcNum", 1);
                        //  线索
                        if ("kfly_xs".equals(develop_source_enumItemCode)){
                            otherNumMap.put("xswwcNum", 1);
                        }
                        //  机会点
                        if ("kfly_jh".equals(develop_source_enumItemCode)){
                            otherNumMap.put("jhwwcNum", 1);
                        }
                        //  自研
                        if ("kfly_zy".equals(develop_source_enumItemCode)){
                            otherNumMap.put("zywwcNum", 1);
                        }
                        //  定制
                        if ("kfly_dz".equals(develop_source_enumItemCode)){

                            if (!"lx4_4".equals(project_rate_enumItemCode) && !"lx5_5".equals(project_rate_enumItemCode)){
                                //非双十
                                otherNumMap.put("fsswwcNum", 1);
                            }else{
                                //双十
                                otherNumMap.put("sswwcNum", 1);
                            }
                        }
                    }

                    otherDataMap.put(memberName, otherNumMap);
                } else {
                    // 如果当前责任人已经在otherDataMap中，则更新其完成和未完成任务的数量
                    Map<String, Object> tempMap = (Map<String, Object>) otherDataMap.get(memberName);
                    int ywcNum_new = 0;
                    int wwcNum_new = 0;
                    int xswwcNum_new = Integer.parseInt(StrKit.str(tempMap.get("xswwcNum")));
                    int jhwwcNum_new = Integer.parseInt(StrKit.str(tempMap.get("jhwwcNum")));
                    int zywwcNum_new = Integer.parseInt(StrKit.str(tempMap.get("zywwcNum")));
                    int fsswwcNum_new = Integer.parseInt(StrKit.str(tempMap.get("fsswwcNum")));
                    int sswwcNum_new = Integer.parseInt(StrKit.str(tempMap.get("sswwcNum")));
                    if ("LCBZT_YWC".equals(enumItemCode)) {
                        ywcNum_new = Integer.parseInt(StrKit.str(tempMap.get("ywcNum"))) + 1;
                        wwcNum_new = Integer.parseInt(StrKit.str(tempMap.get("wwcNum")));
                    } else {
                        ywcNum_new = Integer.parseInt(StrKit.str(tempMap.get("ywcNum")));
                        wwcNum_new = Integer.parseInt(StrKit.str(tempMap.get("wwcNum"))) + 1;

                        //  线索
                        if ("kfly_xs".equals(develop_source_enumItemCode)){
                            xswwcNum_new += 1;
                        }
                        //  机会点
                        if ("kfly_jh".equals(develop_source_enumItemCode)){
                            jhwwcNum_new += 1;
                        }
                        //  自研
                        if ("kfly_zy".equals(develop_source_enumItemCode)){
                            zywwcNum_new += 1;
                        }
                        //  定制
                        if ("kfly_dz".equals(develop_source_enumItemCode)){

                            if ("lx4_4".equals(project_rate_enumItemCode) || "lx5_5".equals(project_rate_enumItemCode)){
                                //双十
                                sswwcNum_new += 1;

                            }else{
                                //非双十
                                fsswwcNum_new += 1;
                            }
                        }
                    }
                    int sumNum_new = Integer.parseInt(StrKit.str(tempMap.get("sumNum"))) + 1;
                    tempMap.put("url", "");
                    tempMap.put("sumNum", sumNum_new);
                    tempMap.put("ywcNum", ywcNum_new);
                    tempMap.put("wwcNum", wwcNum_new);
                    tempMap.put("xswwcNum", xswwcNum_new);
                    tempMap.put("jhwwcNum", jhwwcNum_new);
                    tempMap.put("zywwcNum", zywwcNum_new);
                    tempMap.put("fsswwcNum", fsswwcNum_new);
                    tempMap.put("sswwcNum", sswwcNum_new);

                    otherDataMap.put(memberName, tempMap);
                }
            }
        }
        // 返回处理后的其他数据映射
        return otherDataMap;
    }

    private Map<String, Object> getWwcTypeNumData(String dataType, String projectLevel, String projectLevelValue, Map<String, Object> wwcTypeMap) throws BusinessException {
        if (!"".equals(projectLevel) && !"".equals(projectLevelValue)) {
            CtpEnumItem ctpEnumItem = enumManager.getCtpEnumItem(Long.parseLong(projectLevelValue));
            String xmxjEnumItemCode = StrKit.str(ctpEnumItem.getEnumItemCode());
            for (ProjectLevelEnum projectLevelEnum : ProjectLevelEnum.values()) {
                String key = projectLevelEnum.getKey();
                if (xmxjEnumItemCode.equals(key)) {
                    String value = projectLevelEnum.getValue();
                    if ("lx4_4".equals(key) || !"lx5_5".equals(key)) {
                        if (!wwcTypeMap.containsKey(value)) {
                            wwcTypeMap.put(value, 1);
                        } else {
                            int num = (int) wwcTypeMap.get(value);
                            wwcTypeMap.put(value, num + 1);
                        }
                    } else {
                        if (!wwcTypeMap.containsKey("非双十")) {
                            wwcTypeMap.put("非双十", 1);
                        } else {
                            int num = (int) wwcTypeMap.get("非双十");
                            wwcTypeMap.put("非双十", num + 1);
                        }
                    }
                }
            }
        } else {
            if (dataType.equals("自研")) {
                if (!wwcTypeMap.containsKey("自研")) {
                    wwcTypeMap.put("自研", 1);
                } else {
                    int num = (int) wwcTypeMap.get("自研");
                    wwcTypeMap.put("自研", num + 1);
                }
            } else if (dataType.equals("线索")) {
                if (!wwcTypeMap.containsKey("线索")) {
                    wwcTypeMap.put("线索", 1);
                } else {
                    int num = (int) wwcTypeMap.get("线索");
                    wwcTypeMap.put("线索", num + 1);
                }
            } else if (dataType.equals("机会点")) {
                if (!wwcTypeMap.containsKey("机会点")) {
                    wwcTypeMap.put("机会点", 1);
                } else {
                    int num = (int) wwcTypeMap.get("机会点");
                    wwcTypeMap.put("机会点", num + 1);
                }
            }
        }
        return wwcTypeMap;

    }


    /**
     * 根据类型获取项目其他数据。
     * 该方法主要用于根据不同的类型（如推品、设计、打样、制标）从表单数据中提取出相应的字段值，
     * 并根据这些字段值进行一定的逻辑处理，最终返回一个包含处理结果的Map。
     *
     * @param type     类型代码，用于确定要提取的数据的类型。
     * @param formBean 表单数据豆bean，从中提取字段值。
     * @param masterId 主表ID，用于查询关联的详细数据。
     * @return 包含处理结果的Map，其中键是结果的标识，值是对应的处理结果。
     * @throws BusinessException 如果业务处理过程中出现异常。
     */
    private Map<String, Object> getProjectOtherData(String type, FormBean formBean, Long masterId) throws BusinessException {
        // 初始化结果数据的Map
        Map<String, Object> resultDataMap = new HashMap<String, Object>();
        try {
            // 根据类型代码获取对应的枚举项，用于确定进一步的处理逻辑
            CtpEnumItem ctpEnumItem = getEnumByCode(type);
            // 从系统属性中获取配置的字段名称，用于查询表单数据
            String lcbType = AppContext.getSystemProperty("kanban.lcbType");
            String lcbStatus = AppContext.getSystemProperty("kanban.lcbStatus");
            String subQwwcDateTime = AppContext.getSystemProperty("kanban.subQwwcDateTime");
            String subSjwcDateTime = AppContext.getSystemProperty("kanban.subSjwcDateTime");
            String person_in_charge = AppContext.getSystemProperty("kanban.person_in_charge");
            String tp_task_status = AppContext.getSystemProperty("kanban.tp_task_status");
            String sj_task_status = AppContext.getSystemProperty("kanban.sj_task_status");
            String dy_task_status = AppContext.getSystemProperty("kanban.dy_task_status");
            String zb_task_status = AppContext.getSystemProperty("kanban.zb_task_status");

            // 获取表单的所有字段bean，用于遍历查找匹配的字段
            List<FormFieldBean> formFieldBeans = formBean.getAllFieldBeans();
            // 初始化各种字段名称和表名，用于后续存储匹配到的字段信息
            String lcbTypeFieldName = "";
            String lcbStatusFieldName = "";
            String subQwwcDateTimeFieldName = "";
            String subSjwcDateTimeFieldName = "";
            String person_in_chargeFieldName = "";
            String tp_task_statusFieldName = "";
            String sj_task_statusFieldName = "";
            String dy_task_statusFieldName = "";
            String zb_task_statusFieldName = "";
            String tableName = "";
            String tpTableName = "";
            String sjTableName = "";
            String dyTableName = "";
            String zbTableName = "";

            // 遍历表单字段bean，查找匹配字段并存储其名称和表名
            for (FormFieldBean formFieldBean : formFieldBeans) {
                // 根据字段描述匹配相应的字段名称和表名
                if (formFieldBean.getDesc().equals(lcbType)) {
                    lcbTypeFieldName = formFieldBean.getName();
                    tableName = formFieldBean.getOwnerTableName();
                }
                if (formFieldBean.getDesc().equals(lcbStatus)) {
                    lcbStatusFieldName = formFieldBean.getName();
                }
                if (formFieldBean.getDesc().equals(subQwwcDateTime)) {
                    subQwwcDateTimeFieldName = formFieldBean.getName();
                }
                if (formFieldBean.getDesc().equals(subSjwcDateTime)) {
                    subSjwcDateTimeFieldName = formFieldBean.getName();
                }
                if (formFieldBean.getDesc().equals(person_in_charge)) {
                    person_in_chargeFieldName = formFieldBean.getName();
                }
                if (formFieldBean.getDesc().equals(tp_task_status)) {
                    tp_task_statusFieldName = formFieldBean.getName();
                    tpTableName = formFieldBean.getOwnerTableName();
                }
                if (formFieldBean.getDesc().equals(sj_task_status)) {
                    sj_task_statusFieldName = formFieldBean.getName();
                    sjTableName = formFieldBean.getOwnerTableName();
                }
                if (formFieldBean.getDesc().equals(dy_task_status)) {
                    dy_task_statusFieldName = formFieldBean.getName();
                    dyTableName = formFieldBean.getOwnerTableName();
                }
                if (formFieldBean.getDesc().equals(zb_task_status)) {
                    zb_task_statusFieldName = formFieldBean.getName();
                    zbTableName = formFieldBean.getOwnerTableName();
                }
            }

            // 构建SQL查询语句，用于查询匹配字段的值
            StringBuilder stb = new StringBuilder();
            stb.append("select ").append(lcbStatusFieldName).append(", ");
            stb.append(subQwwcDateTimeFieldName).append(", ").append(subSjwcDateTimeFieldName).append(", ");
            stb.append(person_in_chargeFieldName).append(" from ").append(tableName).append(" where ");
            stb.append(" formmain_id ='").append(masterId).append("'");
            // 根据类型枚举项的ID，添加额外的查询条件
            if (ctpEnumItem != null) {
                stb.append(" and ").append(lcbTypeFieldName).append(" = '").append(ctpEnumItem.getId()).append("'");
            }
//            log.info("查询里程碑明细表数据sql语句:" + stb.toString());
            // 根据条件查询数据列表
            List tpDataList = capDataListSqlHelpManager.selectDataList(stb.toString(), null);
            // 如果查询结果不为空
            if (!tpDataList.isEmpty()) {
                // 遍历查询结果
                for (int i = 0; i < tpDataList.size(); i++) {
                    // 将查询结果的每一条转换为Map
                    Map<String, Object> dataMap = (Map<String, Object>) tpDataList.get(i);
                    // 获取lcb状态值
                    String lcbStatusValue = StrKit.str(dataMap.get(lcbStatusFieldName));
                    // 如果lcb状态值不为空
                    if (!"".equals(lcbStatusValue)) {
                        // 获取负责人信息
                        String person_in_chargeValue = StrKit.str(dataMap.get(person_in_chargeFieldName));
                        // 如果负责人信息不为空
                        if (!"".equals(person_in_chargeValue)) {
                            // 获取负责人的名称
                            String memberName = orgManager.getMemberById(Long.parseLong(person_in_chargeValue)).getName();
                            // 将负责人名称存入结果数据Map中
                            resultDataMap.put("memberName", memberName);
                        }
                        // 获取提交完成时间
                        Object subQwwcDateTimeValue = dataMap.get(subQwwcDateTimeFieldName);
                        // 如果提交完成时间不为空
                        if (!"".equals(StrKit.str(subQwwcDateTimeValue))) {
                            // 将时间转换为指定格式的字符串
                            Date qwwcDateTime_new = sdf.parse(subQwwcDateTimeValue.toString());
                            resultDataMap.put("jhDateTime", new SimpleDateFormat("yyyy-MM-dd").format(qwwcDateTime_new));
                        } else {
                            // 如果提交完成时间为空，则在结果数据Map中存入空字符串
                            resultDataMap.put("jhDateTime", "");
                        }
                        // 获取审批完成时间
                        Object subSjwcDateTimeValue = dataMap.get(subSjwcDateTimeFieldName);
                        // 如果审批完成时间不为空
                        if (!"".equals(StrKit.str(subSjwcDateTimeValue))) {
                            // 将时间转换为指定格式的字符串
                            Date sjwcDateTime_new = sdf.parse(subSjwcDateTimeValue.toString());
                            resultDataMap.put("sjDateTime", new SimpleDateFormat("yyyy-MM-dd").format(sjwcDateTime_new));
                        } else {
                            // 如果审批完成时间为空，则在结果数据Map中存入空字符串
                            resultDataMap.put("sjDateTime", "");
                        }

                        // 根据lcb状态值获取对应的枚举项
                        CtpEnumItem lcbStatusEnumItem = enumManager.getCtpEnumItem(Long.parseLong(lcbStatusValue));
                        // 获取枚举项的代码
                        String enumItemCode = lcbStatusEnumItem.getEnumItemCode();
                        // 如果枚举项的代码等于"LCBZT_YWC"
                        if (enumItemCode.equals("LCBZT_YWC")) {
                            // 在结果数据Map中存入特定值
                            resultDataMap.put("wcl", 100);
                        } else {
                            // 根据类型组装查询SQL
                            String sql = "";
                            if ("LCB_TP".equals(type)) {
                                sql = "select id ," + tp_task_statusFieldName + " from " + tpTableName + " where formmain_id ='" + masterId + "'";
                            } else if ("LCB_SJ".equals(type)) {
                                sql = "select id," + sj_task_statusFieldName + " from " + sjTableName + " where formmain_id ='" + masterId + "'";
                            } else if ("LCB_DY".equals(type)) {
                                sql = "select id," + dy_task_statusFieldName + " from " + dyTableName + " where formmain_id ='" + masterId + "'";
                            } else if ("LCB_ZB".equals(type)) {
                                sql = "select id," + zb_task_statusFieldName + " from " + zbTableName + " where formmain_id ='" + masterId + "'";
                            }
                            log.info("查询任务状态sql语句:" + sql);
                            // 根据SQL查询数据列表
                            List<Map<String, Object>> dataList = capDataListSqlHelpManager.selectDataList(sql, null);
                            // 如果查询结果不为空
                            if (!dataList.isEmpty()) {
                                // 初始化计数器
                                int count = 0;
                                // 遍历查询结果
                                for (int j = 0; j < dataList.size(); j++) {
                                    // 将查询结果的每一条转换为Map
                                    Map<String, Object> otherMap = (Map<String, Object>) dataList.get(j);
                                    // 获取任务状态值
                                    String taskStatusValue = StrKit.str(otherMap.get(tp_task_statusFieldName));
                                    // 如果任务状态值不为空
                                    if (!"".equals(taskStatusValue)) {
                                        // 根据任务状态值获取对应的枚举项
                                        CtpEnumItem taskStatusEnumItem = enumManager.getCtpEnumItem(Long.parseLong(taskStatusValue));
                                        // 如果枚举项的代码等于"RWZT_WC"
                                        if ("RWZT_WC".equals(taskStatusEnumItem.getEnumItemCode())) {
                                            // 计数器加一
                                            count += 1;
                                        }
                                    }
                                }
                                // 计算完成率
                                int dataSum = dataList.size();
                                int wcl = (count * 100) / dataSum;
                                // 将完成率存入结果数据Map中
                                resultDataMap.put("wcl", wcl);
                            } else {
                                // 如果查询结果为空，则在结果数据Map中存入0作为完成率
                                resultDataMap.put("wcl", 0);
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            log.error("获取推品设计打样制标数据报错异常信息:", e);
        }
        return resultDataMap;
    }

    public static void main(String[] args) {
        System.out.println("1");
    }

}
